#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5+10;
int t,n,a[N],b[N],ans;
void dfs(int dep,int lred,int lblue,int acc){
    if(dep>n){ans=max(acc,ans);return;}
    dfs(dep+1,a[dep],lblue,acc+((a[dep]==lred)?a[dep]:0));
    dfs(dep+1,lred,a[dep],acc+((a[dep]==lblue)?a[dep]:0));
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>t;
    while(t--){
        cin>>n;ans=0;
        for(int i=1;i<=n;i++)cin>>a[i];
        for(int i=1;i<=n;i++)b[i]=a[i];
        sort(b+1,b+n+1);
        bool flg = 1;
        for(int i=2;i<=n;i++){
            if(b[i]==b[i-1]){
                flg=0;break;
            }
        }
        if(flg){
            puts("0");
            continue;
        }
        dfs(1,-1,-1,0);
        cout<<ans<<endl;
    }
    return 0;
}
